package com.fss.secondHand.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fss.common.dao.CommonDao;
import com.fss.secondHand.dao.SecondHandDao;
import com.fssDataModels.TbSecondhandItem;
import com.fssDataModels.TbUser;
import com.opensymphony.xwork2.ActionContext;

public class SecondHandServiceImpl implements SecondHandService {
	private CommonDao commonDao;
	private SecondHandDao secondHandDao;
	
	@Override
	public List<TbSecondhandItem> getSecondHandItemList() {
		return this.commonDao.getSecondHandItems(null, new Date());
	}

	@Override
	public int addSecondHandItem(TbSecondhandItem item) {
		item.setCreatedTime(new Date());
		
		Map session = ActionContext.getContext().getSession();
		item.setTbUser((TbUser) session.get("user_login"));
		
		return this.secondHandDao.insertSecondHandItem(item);
	}

	@Override
	public int editSecondHandItem(TbSecondhandItem item) {
		item.setCreatedTime(new Date());
		
		Map session = ActionContext.getContext().getSession();
		item.setTbUser((TbUser) session.get("user_login"));
		return this.secondHandDao.updateSecondHandItem(item);
	}

	@Override
	public int deleteSecondHandItem(TbSecondhandItem item) {
		return this.secondHandDao.deleteSecondHandItem(this.secondHandDao.getSecondHandItem(item.getItemId()));
	}

	@Override
	public TbSecondhandItem getSecondHandItem(int itemId) {
		return this.secondHandDao.getSecondHandItem(itemId);
	}

	public CommonDao getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(CommonDao commonDao) {
		this.commonDao = commonDao;
	}

	public SecondHandDao getSecondHandDao() {
		return secondHandDao;
	}

	public void setSecondHandDao(SecondHandDao secondHandDao) {
		this.secondHandDao = secondHandDao;
	}
	
	
	
}